﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameStateManagement
{
    class projectile
    {
        public Texture2D Texture;

        public Vector2 Position;

        public bool Active;

        public int Damage;

        float projectileRotation;

        Viewport viewport;

        public Vector2 projectileVelocity;

        public int Width
        {
            get { return Texture.Width; }
        }

        public int Height
        {
            get { return Texture.Height; }
        }

        public Vector2 Velocity
        {
            get { return projectileVelocity; }
        }

        public void SetVelocity(Vector2 velocity)
        {
            projectileVelocity = velocity;
        }

      

        //float projectileMoveSpeed;

        public void Initialize(Viewport viewport, Texture2D texture, Vector2 position, Vector2 heading, float rotation)
        {
            Texture = texture;

            Position = position;
            this.viewport = viewport;

            Active = true;

            Damage = 2;

            //projectileMoveSpeed = -1f;
            projectileVelocity = heading;
            projectileRotation = rotation;
        }

        public void Update()
        {
             
            Position += projectileVelocity; 

            if ((Position.X + Texture.Width / 2 > viewport.Width) || (Position.X + Texture.Width / 2 < 0))
                Active = false;

            if ((Position.Y + Texture.Height / 2 > viewport.Height) || (Position.Y + Texture.Height / 2 < 0))
                Active = false;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(Texture, Position, null, Color.White, projectileRotation,
                new Vector2(Width / 2, Height / 2), 1f, SpriteEffects.None, 0f);
        }

        public void setRot(float rot)
        {
            projectileRotation = rot;
        }

        
    }
}
